package com.ruoyi.smartcity.traffic.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.smartcity.traffic.domain.TrafficSignalSchedule;
import com.ruoyi.smartcity.traffic.service.ITrafficSignalScheduleService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 信号灯调度Controller
 * 
 * @author ruoyi
 * @date 2025-02-24
 */
@RestController
@RequestMapping("/smartcity/traffic/schedule")
public class TrafficSignalScheduleController extends BaseController
{
    @Autowired
    private ITrafficSignalScheduleService trafficSignalScheduleService;

    /**
     * 查询信号灯调度列表
     */
    @RequiresPermissions("traffic:schedule:list")
    @GetMapping("/list")
    public TableDataInfo list(TrafficSignalSchedule trafficSignalSchedule)
    {
        startPage();
        List<TrafficSignalSchedule> list = trafficSignalScheduleService.selectTrafficSignalScheduleList(trafficSignalSchedule);
        return getDataTable(list);
    }

    /**
     * 导出信号灯调度列表
     */
    @RequiresPermissions("traffic:schedule:export")
    @Log(title = "信号灯调度", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TrafficSignalSchedule trafficSignalSchedule)
    {
        List<TrafficSignalSchedule> list = trafficSignalScheduleService.selectTrafficSignalScheduleList(trafficSignalSchedule);
        ExcelUtil<TrafficSignalSchedule> util = new ExcelUtil<TrafficSignalSchedule>(TrafficSignalSchedule.class);
        util.exportExcel(response, list, "信号灯调度数据");
    }

    /**
     * 获取信号灯调度详细信息
     */
    @RequiresPermissions("traffic:schedule:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(trafficSignalScheduleService.selectTrafficSignalScheduleById(id));
    }

    /**
     * 新增信号灯调度
     */
    @RequiresPermissions("traffic:schedule:add")
    @Log(title = "信号灯调度", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TrafficSignalSchedule trafficSignalSchedule)
    {
        return toAjax(trafficSignalScheduleService.insertTrafficSignalSchedule(trafficSignalSchedule));
    }

    /**
     * 修改信号灯调度
     */
    @RequiresPermissions("traffic:schedule:edit")
    @Log(title = "信号灯调度", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TrafficSignalSchedule trafficSignalSchedule)
    {
        return toAjax(trafficSignalScheduleService.updateTrafficSignalSchedule(trafficSignalSchedule));
    }

    /**
     * 删除信号灯调度
     */
    @RequiresPermissions("traffic:schedule:remove")
    @Log(title = "信号灯调度", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(trafficSignalScheduleService.deleteTrafficSignalScheduleByIds(ids));
    }
}
